<template>
  <view>
    <login-page @tapLogin="tapLogin" @tapCode="flushCode" @tapRegister="tapRegister" :codeUrl="codeUrl" @wxAuth="wxLogin()"></login-page>
  </view>
</template>
<script setup>
import { computed, getCurrentInstance, reactive, ref } from "vue";
import { onLoad, onShow, onPullDownRefresh, onReachBottom } from "@dcloudio/uni-app";
import request from "@/lib/request.js";
import useAuthStore from "@/store/module/auth.js";
import useWxStore from "@/store/module/wx.js";
const authStore = useAuthStore();
const wxStore = useWxStore();
import { handleRes, showLoading, closeLoading } from "@/lib/common.js";
const codeUrl = ref("");
const uuid = ref("");
// 登录页面相关时间
function tapLogin(e) {
  let data = {
    userName: e.loginId,
    password: e.loginPwd,
    uuid: uuid.value,
    code: e.code,
  };
  showLoading("登陆中");
  authStore.doLogin(data).then((res) => {
    console.log(res);
    closeLoading();
    // 路径跳转
    if (res.success) {
      uni.switchTab({
        url: "/custom/edu/pages/index/index",
      });
    } else {
      flushCode();
    }
  });
}

function wxLogin() {
  showLoading("微信快速登录中");
  wxStore.wxAuthPromise().then((r) => {
    console.log(r);
    closeLoading();
    if (r) {
      uni.switchTab({
        url: "/custom/edu/pages/index/index",
      });
    }
  });
}

// 点击注册
function tapRegister(e) {}
onLoad((options) => {});
// 刷新验证码
function flushCode() {
  request({
    url: "/system/captcha",
    method: "GET",
  }).then((res) => {
    //console.log(res)
    //handleRes(res)
    if (res.code == 200) {
      codeUrl.value = res.data.img;
      uuid.value = res.data.uuid;
    }
  });
}
</script>
<style></style>
